package com.ferris.composite;

import java.util.ArrayList;

/**
 *  房间 ，门管理着所以动物的进出
 * @author Administrator
 *
 */
public class House implements Door{
	private ArrayList<Animal> animals=new ArrayList<Animal>();
	
	private static House house;
	
	public static House getHouseInstance(){
		if(house==null){
			synchronized (House.class) {
				if(house==null){
					return new House();
				}
			}
		}
		return house;
	}

	
	@Override
	public void addAnimal(Animal animal) {
		// TODO Auto-generated method stub
		if(!animals.contains(animal)){
			animals.add(animal);
		}
	}

	@Override
	public void removeAnimal(Animal animal) {
		// TODO Auto-generated method stub
		if(animals.contains(animal)){
			animals.remove(animal);
		}
	}

	@Override
	public void removeAllAnimal() {
		// TODO Auto-generated method stub
		if(animals.size()>0){
			animals.clear();
		}
	}

	@Override
	public int getAnimalCount() {
		// TODO Auto-generated method stub
		return animals==null?0:animals.size();
	}

	@Override
	public ArrayList<Animal> getAnimals() {
		// TODO Auto-generated method stub
		return animals;
	}

}
